package com.guaju.yueshangLife.activity;

import android.app.ActivityManager;
import android.databinding.DataBindingUtil;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;

import com.guaju.yueshangLife.R;
import com.guaju.yueshangLife.base.BaseActivity;
import com.guaju.yueshangLife.databinding.ActivityNetErrorBinding;
import com.guaju.yueshangLife.global.BaseApplication;
import com.guaju.yueshangLife.net.NetworkUtil;
import com.guaju.yueshangLife.utils.AppManager;
import com.guaju.yueshangLife.utils.PreferenceUtil;
import com.guaju.yueshangLife.utils.ToastUtil;
import com.lljjcoder.style.citylist.Toast.ToastUtils;

import java.util.IllegalFormatCodePointException;

public class NetErrorActivity extends BaseActivity {


    private ActivityNetErrorBinding binding;
    private long firstTime;

    @Override
    protected void loadViewLayout() {
        binding = DataBindingUtil.setContentView(this,R.layout.activity_net_error);

    }

    @Override
    protected void bindViews() {

    }

    @Override
    protected void processLogic(Bundle savedInstanceState) {

    }

    @Override
    protected void setListener() {
        binding.btRetry.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (NetworkUtil.isConnected(NetErrorActivity.this)){
                    BaseApplication.getInstance().setRetryable(true);
                    finish();
                }else{
                    showToast("网络异常，请检查~");
                }
            }
        });
    }


    @Override
    public void onBackPressed() {
        long secondTime = System.currentTimeMillis();
        if (secondTime - firstTime > 2000) {
            ToastUtil.show("再按一次退出程序");
            firstTime = secondTime;
        } else {
            BaseApplication.getInstance().setFinishable(true);
            finish();
            AppManager.getAppManager().finishAllActivity();
            ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
            manager.killBackgroundProcesses(getPackageName());

        }
    }


}
